using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["jsuserid"]==null)
        {
            lblHeader.Text = "New Registration";
            this.Title = "::New Registration";
            literalMessage.Visible = true;
            txtEmail.Enabled=true;
            btnSave.Text = "I Agree";
            
            Page.ClientScript.RegisterClientScriptBlock(
                    this.GetType(), "ClientScriptFunctionAgree",
                    ClientScriptFunctionAgree(), true);       
            btnSave.Attributes.Add("onclick","return validateAgree();");
            trPassword.Visible = true;
            trRetype.Visible = true;
                
        }
        else
        {
            this.Title = "::Update Login Information";
            literalMessage.Visible=false;
            lblHeader.Text = "Update Login Information";
            txtEmail.Enabled = false;
            txtEmail.Text= Session["jsemail"].ToString();
            btnSave.Text="Update";
            trPassword.Visible = false;
            trRetype.Visible = false;
        }
    }
    string ClientScriptFunctionAgree()
    {
        string strScript = "";
        strScript =
        "function validateAgree()\n" +
        "{\n if(!document.getElementById('" 
        + chkAgree.ID + "').checked){alert('"
        +"Please check Agree checkbox "+
        "if you agree our policy');"+
        "return false;} return true;" +        
        " \n}\n";
        return strScript;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        
                    
        if(txtEmail.Text!="")
        {
            SQLServerClass cls = new SQLServerClass();
            if (Session["jsuserid"] == null)
            {                                
                string userID=cls.NewJSAccount(
                txtEmail.Text, 
                txtPassword.Text,
                txtFirstName.Text, 
                txtLastName.Text,
                (chkNewLetter.Checked)?"1":"0",
                (chkJobAlert.Checked)?"1":"0",
                (chkCompanyInfo.Checked)?"1":"0");
                if(cls.ErrorCode==2627)
                {
                    literalError.Text=
                    "Sorry! RCV database show that "+
                    "someone has registered a job "+
                    "seeker account with this e-mail "+
                    "address. If you have previously "+
                    "registered under this e-mail "+
                    "address and forgotten your "+
                    "password, you can request for "+
                    "your password <a href=\""+
                    "forgotpassword.aspx\">here</a>";
                }
                else if (cls.ErrorMessage  !="")
                {
                    literalError.Text =
                    "Error: " + cls.ErrorMessage;
                }
                else               
                {
                    Session.Add("jsuserid", userID);
                    Session.Add("jsemail", txtEmail.Text);
                    Session.Add("jsfullname", 
                    txtFirstName.Text + " " + txtLastName.Text);
                    literalError.Text = "";
                                        
                    Response.Redirect("personal.aspx");                   
                }
            }
            else
            {
                literalError.Text = "Updated successfull";

                Session.Add("jsfullname", txtFirstName.Text + " " + txtLastName.Text);
            }
        }
    }
}
